<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

class Region_model extends MY_Model {

    function __construct() {
        parent::__construct("region", "code", Array());
    }

    protected function read($where = Array(), $fetchForeign = false, $depth = 1, $page = -1, $limit = 10) {
        $results = parent::read($where, $fetchForeign, $depth, $page, $limit);

        $this->load->model("Provinsi_model");
        foreach ($results as $result) {
            $result->vector = "";
            // aggregate from provinces
            foreach ($this->Provinsi_model->findAll(Array("region_code" => $result->code)) as $prov) {
                if ($result->vector != "") {
                    //$result->vector .= ";";
                }
                //$result->vector .= $prov->vector;
            }
        }

        return $results;
    }

}